﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
struct stu
{
	int age;
	char name[50];
	float score;
};

int main1()
{
	struct stu s1 = {.score = 56.2,.age = 19,.name = "lisi"};  
	printf("%f %d %s",s1.score,s1.age,s1.name);
	return 0;
}
//练习1
struct S1
{
	char c1;
	int i;
	char c2;
};

//练习2
struct S2
{
	char c1;
	char c2;
	int i;
};
struct S3
{
	double d;
	char c;
	int i;
};
//练习4-结构体嵌套问题
struct S4
{
	char c1;
	struct S3 s3;
	double d;
};
int main2()
{
	printf("%d\n", sizeof(struct S1));  // 12
	printf("%d\n", sizeof(struct S3));
	printf("%d\n", sizeof(struct S4));
	printf("%d\n", sizeof(struct S2));  // 8
	return 0;
}
#include <stdio.h>
#pragma pack(1)//设置默认对⻬数为1
struct S8
{
	char c1;
	int i;
	char c2;
};
#pragma pack()//取消设置的默认对⻬数，还原为默认
int main3()
{
	//输出的结果是什么？
	printf("%d\n", sizeof(struct S8));
	return 0;
}
struct A
{
	int a : 2;
	int b : 5;
	char c : 3;
	char d : 2;
}A;
int main4()
{
	A.a = 10;  // 二进制： 1010 但是a 只占2个比特位，所以取走 10
	A.b = 12;  //          1100                           取走01100
	A.c = 3;   //          11                                 011
	A.d = 4;   //          100                                 00
	printf("%d", sizeof(struct A));   // 8
	return 0;
}
struct S
{
	char a : 3;
	char b : 4;
	char c : 5;
	char d : 4;
};
int main10()
{
	struct S q = { 0 };
	q.a = 10;
	q.b = 12;
	q.c = 3;
	q.d = 4;
	printf("%d\n", sizeof(struct S));   // 3字节
	return 0;
}
struct A
{
	int _a : 2;
	int _b : 5;
	int _c : 10;
	int _d : 30;
};
int main()
{
	struct A sa = { 0 };
	scanf("%d", &sa._b);//这是错误的

	//正确的⽰范
	int b = 0;
	scanf("%d", &b);
	sa._b = b;
	return 0;
}